package org.example.service.impl;

import org.example.mapper.DepartmentMapper;
import org.example.pojo.*;
import org.example.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class DepartmentServiceImpl implements DepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;

    /**
     * 分页查询部门信息
     * @return分页的部门信息
     */
    @Override
    public List<Department> showDepartmentAllByPage() {

        return departmentMapper.selectDepartmentAllByPage();
    }

    /**
     * 关键字搜索
     * @param message
     * @return
     */
    @Override
    public List<Department> showDepartmentsByName(String message) {
//        int begin=(page-1)*limit;
//        Map<String,Object> map=new HashMap<>();
//        map.put("dName",dName);
//        map.put("page",begin);
//        map.put("limit",limit);
        return departmentMapper.selectDepartmentByNameAndPage(message);
    }

    public List<Department> showDepartmentById(Integer dId){
        return departmentMapper.selectDepartmentById(dId);
    }

    /**
     * 修改部门信息
     * @param departmentRegister
     * @return受影响行数
     */
    @Override
    public boolean updateDepartment(DepartmentRegister departmentRegister) {
        return departmentMapper.updateDepartment(departmentRegister)>0;
    }

    /**
     * 通过did删除部门
     * @param dId
     * @return返回受影响的行数
     */
    @Override
    public int deletDepartment(int dId) {
        return departmentMapper.deletDepartment(dId);
    }

    /**
     * 添加部门
     * @param dpartmentAdd
     * @return受影响行数
     */
    @Override
    public boolean addNewDepartment(DpartmentAdd dpartmentAdd) {
        return departmentMapper.insertDepartment(dpartmentAdd)>0;
    }


    /**
     * 查询部门架构
     * @return
     */
    public List<Map<String,Object>> showDepartmentArch(){
        return  departmentMapper.selectDepartmentArch();
    }

    /**
     * 通过部门名称查询员工
     * @param dName
     * @return员工姓名
     */
    @Override
    public List<DepartmentEmployee> showEmployeeNameByDepartment(String dName) {
        return departmentMapper.selectEmployeeNameByDepartment(dName);
    }


    /**
     * 查询员工信息
     * @param eId
     * @return
     */
    @Override
    public DepartmentEmployee showEmployeeById(int eId) {
        return departmentMapper.selectEmployeeById(eId);
    }

    /**
     *
     * 查询部门id和name
     * @return
     */
    @Override
    public List<DepartmentIdAndName> showDepartmentIdAndName() {
        return departmentMapper.selectDepartmentIdAndName();
    }

    /**
     * 查询部门等级
     * @return
     */
    public List<String> showDepartmentFirst(int dParentId){
        return departmentMapper.selectDepartmentFirst(dParentId);
    }
}
